<?php
/**
 * キャンペーンエントリー関連モデル<br />
 *
 * @package apamanshop
 * @author H.Imamura
 * @copyright
 */
class Inquiry_Model_Campaign extends Inquiry_Model_Apibase
{
	/**
	 * 汎用キャンペーン応募データを登録する
	 *
	 * @param array $inquiryData 登録情報
	 * @return
	 */
	public function SetOpenCampaignEntry($entryData)
	{
		$ret = false;
		$db_params = array();
		$sql  = "";
		$sql .= "INSERT INTO CAMPAIGN_USER.C01_OPEN_CAMPAIGN_ENTRY (";
		$sql .= "   C01_CAMPAIGN_CD";
		$sql .= "  ,C01_ENTRY_DATE";
		$sql .= "  ,C01_NAME";
		$sql .= "  ,C01_KANA";
		$sql .= "  ,C01_ZIP";
		$sql .= "  ,C01_PREF_CD";
		$sql .= "  ,C01_PREF";
		$sql .= "  ,C01_ADDRESS";
		$sql .= "  ,C01_MAIL";
		$sql .= "  ,C01_MOBILE_MAIL";
		$sql .= "  ,C01_TEL";
		$sql .= "  ,C01_MOBILE_TEL";
		$sql .= "  ,C01_FAX";
		$sql .= "  ,C01_SEX";
		$sql .= "  ,C01_BIRTHDAY";
		$sql .= "  ,C01_AGE";
		$sql .= "  ,C01_KIBOU_RENRAKU_ZIKAN";
		$sql .= "  ,C01_COMMENT";
		$sql .= "  ,C01_FREE";
		$sql .= "  ,C01_DEL_FLG";
		$sql .= "  ,C01_TOIAWASE_ID";
		$sql .= "  ,C01_TOUROKUBI";
		$sql .= "  ,C01_KOUSHINBI";
		$sql .= ") VALUES (";
		$sql .= "   :campaignCd";
		$sql .= "  , sysdate";
		$sql .= "  ,:name";
		$sql .= "  ,:kana";
		$sql .= "  ,:zip";
		$sql .= "  ,:prefCd";
		$sql .= "  ,:pref";
		$sql .= "  ,:address";
		$sql .= "  ,:mail";
		$sql .= "  ,:mobileMail";
		$sql .= "  ,:tel";
		$sql .= "  ,:mobileTel";
		$sql .= "  ,:fax";
		$sql .= "  ,:sex";
		$sql .= "  ,:birthday";
		$sql .= "  ,:age";
		$sql .= "  ,:kiboRenrakuZikan";
		$sql .= "  ,:commentMsg";
		$sql .= "  ,:free";
		$sql .= "  ,:delFlg";
		$sql .= "  ,:toiawaseId";
		$sql .= "  , sysdate";
		$sql .= "  , null";
		$sql .= ")";
		
		$db_params['campaignCd'] = $entryData['CAMPAIGN_CD'];
		if (isset($entryData['NAME'])) {
			$db_params['name'] = $entryData['NAME'];
		} else {
			$db_params['name'] = '';
		}
		if (isset($entryData['KANA'])) {
			$db_params['kana'] = $entryData['KANA'];
		} else {
			$db_params['kana'] = '';
		}
		if (isset($entryData['ZIP'])) {
			$db_params['zip'] = $entryData['ZIP'];
		} else {
			$db_params['zip'] = '';
		}
		if (isset($entryData['PREF_CD'])) {
			$db_params['prefCd'] = $entryData['PREF_CD'];
			if (!isset($entryData['PREF'])) {
				$db_params['pref']   = Apm_Config_Shop::$PREF_LIST[$entryData['PREF_CD']];
			}
		} else {
			$db_params['prefCd'] = '';
			$db_params['pref']   = '';
		}
		if (isset($entryData['PREF'])) {
			$db_params['pref']   = $entryData['PREF'];
		}
		if (isset($entryData['ADDRESS'])) {
			$db_params['address'] = $entryData['ADDRESS'];
		} else {
			$db_params['address'] = '';
		}
		if (isset($entryData['MAIL'])) {
			$db_params['mail'] = $entryData['MAIL'];
		} else {
			$db_params['mail'] = '';
		}
		if (isset($entryData['MOBILE_MAIL'])) {
			$db_params['mobileMail'] = $entryData['MOBILE_MAIL'];
		} else {
			$db_params['mobileMail'] = '';
		}
		if (isset($entryData['TEL'])) {
			$db_params['tel'] = $entryData['TEL'];
		} else {
			$db_params['tel'] = '';
		}
		if (isset($entryData['MOBILE_TEL'])) {
			$db_params['mobileTel'] = $entryData['MOBILE_TEL'];
		} else {
			$db_params['mobileTel'] = '';
		}
		if (isset($entryData['FAX'])) {
			$db_params['fax'] = $entryData['FAX'];
		} else {
			$db_params['fax'] = '';
		}
		if (isset($entryData['SEX'])) {
			$db_params['sex'] = $entryData['SEX'];
		} else {
			$db_params['sex'] = '';
		}
		if (isset($entryData['BIRTH_DAY'])) {
			$db_params['birthday'] = $entryData['BIRTH_DAY'];
		} else {
			$db_params['birthday'] = '';
		}
		if (isset($entryData['AGE'])) {
			$db_params['age'] = $entryData['AGE'];
		} else {
			$db_params['age'] = '';
		}
		if (isset($entryData['KIBO_RENRAKU_ZIKAN'])) {
			$db_params['kiboRenrakuZikan'] = $entryData['KIBO_RENRAKU_ZIKAN'];
		} else {
			$db_params['kiboRenrakuZikan'] = '';
		}
		if (isset($entryData['COMMENT'])) {
			$db_params['commentMsg'] = $entryData['COMMENT'];
		} else {
			$db_params['commentMsg'] = '';
		}
		if (isset($entryData['FREE'])) {
			$db_params['free'] = $entryData['FREE'];
		} else {
			$db_params['free'] = '';
		}
		if (isset($entryData['DEL_FLG'])) {
			$db_params['delFlg'] = $entryData['DEL_FLG'];
		} else {
			$db_params['delFlg'] = '0';
		}
		if (isset($entryData['W25_TOIAWASE_ID'])) {
			$db_params['toiawaseId'] = $entryData['W25_TOIAWASE_ID'];
		} else {
			$db_params['toiawaseId'] = '';
		}
		
		//トランザクション開始
		$db = $this->getDbConnection();
		$this->startTransaction($db);
		try {
			// DB登録
//__log_debug_ex($sql);
//__log_debug_ex($db_params);
			$count = $this->dbExecQuery($sql, $db_params, $db);
//__log_debug_ex($count);
			if ($count == 1) {
				// コミット
				$this->commitTransaction($db);
				$ret = true;
			} else {
				// ロールバック
				$this->rollbackTransaction($db);
			}
		} catch (Exception $e) {
			// ロールバック
			$this->rollbackTransaction($db);
			// エラーメッセージをログに書き出す
			__log_debug(__FILE__, __LINE__, __METHOD__, $e->getMessage());
		}
		// DBクローズ
		$db->closeConnection();
		
		return $ret;
	}

}
?>
